// pages/interface/interface.js
//获取应用实例
// pages/eventdetails/eventdetails.js
var util = require('../../utils/util.js');
var commonService = require('../../services/commonService.js');
var activityService = require('../../services/activityService.js');
var WxParse = require('../../wxParse/wxParse.js');
var app = getApp()
Page({
  data:{
    lives:0,
    activitys: [],
  },
   liveClick: function( e ) {  
    var that = this;  
    if( this.data.lives === e.currentTarget.dataset.live ) {  
      return false;  
    } else {  
      that.setData( {  
        lives: e.currentTarget.dataset.live  
      })  
    }  
  },
  clickDetails:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../eventdetails/eventdetails?id='+id +'&join=1'
    });
  },
  releaseActivity: function (e) {
    this.getJoinActivity(1);
  },
  onLoad: function () {
    var that = this;
    var today = new Date();
    this.getJoinActivity();
    },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  getJoinActivity: function (append){
    var that = this;
    activityService.getJoinActivity({
      user_id: app.globalData.sysUserInfo.userId,
      success:function(res){
        var activities = [];

        if (append == 1) {
          activities = that.data.activities;
        }

        for (var i = 0; i < res.length; i++) {
          var data = res[i];
          // date.replace(/-/g, "/")
          data.start_time = util.makeDateTimeToPretty(new Date(data.getActivities.active_time_start.replace(/-/g, "/")), true);
          data.end_time = util.makeDateTimeToPretty(new Date(data.getActivities.active_time_end.replace(/-/g, "/")), true);
          data.remainJoinNum = data.volunteer_num - data.join_num;
          activities.push(res[i]);
        }
        that.setData({
          activitys: activities
        })
      }
    })
  },
  backTopPrevNavigate: function () {
    wx.navigateBack()
  }
})